import { IPagination } from './pagination'
import { IQueryParams } from './queryParams'
import { propertyMap } from '@shared/decorators/property-map'
import { ITrade } from './trade'
import { Store, IQRRouteOfStore, StoreFull } from './store'
import { QrChannel } from './acquirer'
import { IHoldReleaseDetail, IChargeBack } from './operation'
import { PostRiskScheme } from './post-risk-control'

export interface ITaskQueryParams extends IQueryParams {
  submittedAtFrom: string
  submittedAtTo: string
  updatedAtFrom: string
  updatedAtTo: string
}

export class Task {
  audiFlowID: string
  auditLogs: IAuditLog[] = []
  auditObject: string
  auditStepName?: string
  auditType: string
  creator: string
  currentStep: number
  insCode: string
  jobID: string
  lastOperator?: string
  status: string
  preSteps?: string[] = []
  data: ITaskData
  createTime: string
  updateTime: string
  preOperators?: string[]
  currentOperators?: string[]
  operation?: ETaskOperation
}

export enum ETaskOperation {
  Update = 'update',
  TransRelease = 'transRelease',
  Restitution = 'restitution',
  ChargeBack = 'chargeback',
}
export enum ETaskPostRiskOperation {
  CreatePostRisk = 'create post risk scheme',
  UpdatePostRisk = 'update post risk scheme',
  DeletePostRisk = 'delete post risk scheme',
}
export interface IAuditLog {
  auditOperation: 'string'
  auditStepID: number
  jobID: string
  operator: string
  createTime: string
}

export interface IReleaseTaskData {
  holdDetail?: IHoldReleaseDetail
  releaseDetail?: IHoldReleaseDetail
}

export interface IStoreTaskData {
  storeData?: StoreFull // 门店任务
  origStoreData?: StoreFull // 旧的门店信息，用于更新门店时
}

export interface IChargeBackTaskData {
  wildErrorOrig: ITrade
  wildErrorMsg: IChargeBack
}

export interface ITaskData extends IReleaseTaskData, IStoreTaskData, IPostRiskTaskData, IChargeBackTaskData {
  dataStatus: ETaskStatusMap
  jobID: string
  originTrans?: ITrade
  trans?: ITransInfo
  createTime: string
  updateTime: string
}

export interface IPostRiskTaskData {
  postRiskSchemeData?: PostRiskScheme // 事后风控方案任务
  origPostRiskSchemeData?: PostRiskScheme // 旧的事后风控方案信息，用于更新门店时
}
export interface ITransInfo {
  currency: string
  intMerCode: string
  intStoreCode: string
  orderNum: string
  originOrderNum: string
  platform: string
  refundDetail: string
  txamt: string
  username: string
}
export interface ITaskPagination extends IPagination {
  data: Task[]
}

export enum ETaskCategory {
  all = 'all',
  submitted = 'submitted',
  todo = 'todo',
  done = 'done',
}

export const TaskTypeMap = {
  all: '全部',
  submitted: '我提交的任务',
  todo: '待处理的任务',
  done: '已处理的任务',
}

export enum ETaskType {
  transRefund = 'transRefund',
  store = 'store',
  riskControl = 'riskControl',
  operation = 'operation',
}

export enum ETaskStatus {
  Init = 'init',
  Auditing = 'auditing',
  Approved = 'approved',
  Rejected = 'rejected',
}

export enum ETaskTypeMap {
  'transRefund' = 'TASK.TYPE.TRANSREFUND',
  'store' = 'TASK.TYPE.STORE',
  'riskControl' = 'TASK.TYPE.RISKCONTROL',
  'operation' = 'TASK.TYPE.OPERATION',
}

export enum ETaskStatusMap {
  'auditing' = 'TASK.STATUS.AUDITING',
  'approved' = 'TASK.STATUS.APPROVED',
  'rejected' = 'TASK.STATUS.REJECTED',
}

export enum ETaskOperationMap {
  'create' = 'AUDIT.OPERATION.CREATE',
  'approve' = 'AUDIT.OPERATION.APPROVE',
  'reject' = 'AUDIT.OPERATION.REJECT',
}

export interface IEnrolReq {
  auditType: string
  insCode: string
  resourceId: string // intStoreCode || riskCode
}

export interface IEnrolRes {
  token: string
}
